package com.niit.bc.bean;

import java.util.HashMap;
import java.util.Map;

public class CartBean {

    private UserBean userBean;// 得到UserBean对象
    private BookBean bookBean;// 得到BookBean对象

    private int bookCount;// 同一本书购买的数量
    private double bookAllPrice;// 同一本书购买的总价钱
    private double cartAllPrice;// 购物车的总价钱


    private int bookNum = 0;//这个是计算购物车里面的图书件数，其他地方用不上


    /***
     * 一下为购物车页面显示需要的属性，其他地方不需要
     * @return
     */
    private int bookId;
    private int Num;//ku cun liang
    private String bookName;
    private String bookPhoto;
    private double bookPrice;

    public UserBean getUserBean() {
        return userBean;
    }

    public void setUserBean(UserBean userBean) {
        this.userBean = userBean;
    }

    public BookBean getBookBean() {
        return bookBean;
    }

    public void setBookBean(BookBean bookBean) {
        this.bookBean = bookBean;
    }

    public int getBookCount() {
        return bookCount;
    }

    public void setBookCount(int bookCount) {
        this.bookCount = bookCount;
    }

    public double getBookAllPrice() {
        return bookAllPrice;
    }

    public void setBookAllPrice(double bookAllPrice) {
        this.bookAllPrice = bookAllPrice;
    }

    public double getCartAllPrice() {
        return cartAllPrice;
    }

    public void setCartAllPrice(double cartAllPrice) {
        this.cartAllPrice = cartAllPrice;
    }

    public int getBookNum() {
        this.bookNum = this.myCart.size();
        return bookNum;
    }

    public void setBookNum(int bookNum) {
        bookNum = this.myCart.size();
        this.bookNum = bookNum;
    }

    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {

        this.bookId = bookId;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {

        this.bookName = bookName;
    }

    public String getBookPhoto() {
        return bookPhoto;
    }

    public void setBookPhoto(String bookPhoto) {
        this.bookPhoto = bookPhoto;
    }

    public double getBookPrice() {
        return bookPrice;
    }

    public void setBookPrice(double bookPrice) {
        this.bookPrice = bookPrice;
    }

    public int getNum() {
        return Num;
    }

    public void setNum(int num) {
        this.Num = num;
    }


    public Map <Integer, Integer> myCart = new HashMap <Integer, Integer>();

    public void addBooks(int bookId, int bookCount) { // 把商品加入购物车
        if (myCart.containsKey(bookId)) {// 购物车中存在此商品则累加个数
            int Temp_Count = ((Integer) myCart.get(bookId)).intValue();
            Temp_Count = Temp_Count + bookCount;
            myCart.put(bookId, new Integer(Temp_Count));
        } else {// 购物车中不存在此商品
            myCart.put(bookId, new Integer(bookCount));
        }
    }

    public boolean minusBooks(int bookId, int Books_Count) { // 把商品从购物车中拿出
        if (myCart.containsKey(bookId)) {// 购物车中存在此商品则减少个数
            int Temp_Count = ((Integer) myCart.get(bookId)).intValue();
            Temp_Count = Temp_Count - Books_Count;
            if (Temp_Count <= 0)
                deleteBooks(bookId);
            else
                myCart.put(bookId, new Integer(Temp_Count));
            return true;
        } else {// 购物车中不存在此商品
            return false;
        }
    }

    public Map <Integer, Integer> listmyCart() {// 得到购物车中所有商品
        return myCart;
    }

    public boolean deleteBooks(int bookId) {// 从购物车中删除一件商品
        if (myCart.remove(bookId) == null)
            return false;
        else
            return true;
    }

    public boolean deleteAllBooks() {// 从购物车中删除所有商品
        myCart.clear();
        if (myCart.isEmpty())
            return true;
        else
            return false;
    }

    public Map <Integer, Integer> getmyCart() {
        return myCart;
    }

    public void setmyCart(HashMap <Integer, Integer> myCart) {
        this.myCart = myCart;
    }

}
